import numpy as np
import cv2
import matplotlib.pyplot as plt
from data_preparation import *
from sklearn.cluster import KMeans
from Classifying_utils import *
from utils2 import JS_D



kmeans_labels = KMeans(n_clusters=3).fit(round2_training_feat).labels_
# plt.figure()
# plt.scatter(round2_training_feat_pca[:,0], round2_training_feat_pca[:,1], c = kmeans_labels, cmap=cmap)
# 计算每个聚类簇的平均特征
avg_feat0 = np.average(round2_training_feat[kmeans_labels == 0], axis=0)
avg_feat1 = np.average(round2_training_feat[kmeans_labels == 1], axis=0)
avg_feat2 = np.average(round2_training_feat[kmeans_labels == 2], axis=0)

kmeans_predicted_labels = []
for cur_feat in round2_feat:
    sims = [np.sum(cur_feat * avg_feat0), np.sum(cur_feat * avg_feat1), np.sum(cur_feat * avg_feat2)]
    kmeans_predicted_labels.append(sims.index(max(sims)))
# print('<================All frames classification report================>')
# print(classification_report(rf_label_allFrame, kmeans_predicted_labels, digits=3))
# print('<================All frames classification report================>')
print(get_classify_acc(kmeans_predicted_labels, rf_label_allFrame, boundary_range=0.2))





profile_predicted_labels = []
straight_scp, turn_scp, alert_scp = get_scp(round2_ds,[1080,21095,10727])
for cur_ds in round2_ds:
    js_d = [JS_D(straight_scp, cur_ds), JS_D(turn_scp, cur_ds), JS_D(alert_scp, cur_ds)]
    profile_predicted_labels.append(js_d.index(min(js_d)))
print(fuzzy_boundary_classifying(profile_predicted_labels, rf_label_allFrame, boundary_range=0.2))